﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
#if WINDOWS_PHONE
using Microsoft.Xna.Framework.Input.Touch;
#endif
#if WINDOWS
using Microsoft.Xna.Framework.Storage;
#endif
using Microsoft.Xna.Framework.Media;
using Neat;
using Neat.MenuSystem;
using Neat.EasyMenus;
using Neat.GUI;
using Neat.Mathematics;
using Neat.Graphics;
using System.IO;
namespace RiverRaidX
{
    public partial class RiverRaidGame : Screen
    {
        #region Setup
        public override void Initialize()
        {
            base.Initialize();

            lb = new LineBrush(game.GraphicsDevice, 1);

            Reset();
        }

        public override void LoadContent()
        {
            game.LoadTexture(@"Sprites\RiverRaid\bridge");
            game.LoadTexture(@"Sprites\RiverRaid\fuel");
            game.LoadTexture("heli", 1, @"Sprites\RiverRaid\heli", @"Sprites\RiverRaid\heli1");
            game.LoadTexture(@"Sprites\RiverRaid\house");
            game.LoadTexture(@"Sprites\RiverRaid\jet");
            game.LoadTexture(@"Sprites\RiverRaid\raider");
            game.LoadTexture(@"Sprites\RiverRaid\raider_mv");
            game.LoadTexture(@"Sprites\RiverRaid\road");
            game.LoadTexture(@"Sprites\RiverRaid\Ship");
            game.LoadTexture(@"Sprites\RiverRaid\tree");
            game.LoadTexture(@"Sprites\RiverRaid\gauge");

            game.LoadSounds("explosion",
                //@"Sounds\RiverRaid\explosion_small",
                //@"Sounds\RiverRaid\explosion1",
                @"Sounds\RiverRaid\explosion2");
            game.LoadSound(@"Sounds\RiverRaid\engine_start");
            game.LoadSound(@"Sounds\RiverRaid\engine");
            game.LoadSounds("launch",
                //@"Sounds\RiverRaid\launch",             
                @"Sounds\RiverRaid\launch2");

            game.LoadSounds("fuel",
                @"Sounds\RiverRaid\fuel"
                //@"Sounds\RiverRaid\fuel_full"
                );

            game.LoadSound(@"Sounds\RiverRaid\static");

            game.LoadTexture(@"Sprites\RiverRaid\explosion_sheet");
            //game.CreateSprite("explosion", "explosion_sheet", new Vector2(320 / 5), 5, true);
            game.CreateSprite("explosion", "explosion_sheet", new Rectangle(0,0,64,64), 5, 5, true);
            game.LoadFont(@"Fonts\Vani35");

            target = new RenderTarget2D(game.GraphicsDevice,
                game.GraphicsDevice.PresentationParameters.BackBufferWidth, game.GraphicsDevice.PresentationParameters.BackBufferHeight,
                false, SurfaceFormat.Color, DepthFormat.None, 1, RenderTargetUsage.PreserveContents);
            
            game.Console.Run("rr_noplayer true");

            base.LoadContent();
        }

        void InitForm()
        {
            Form = new Neat.GUI.Form(game);
            Form.MouseSpeed = 0;

            Box b = new Box();
            Form.NewControl("dashboard", b);
            b.TintColor = Color.LightGray;
            b.Position = new Vector2(0, game.GameHeight - 120);
            b.Size = new Vector2(game.GameWidth, 120);

            fuelBg = new Image();
            Form.NewControl("fuelBg", fuelBg);
            fuelBg.BackgroundImage = "gauge";
            fuelBg.Position = new Vector2(600, game.GameHeight - 100);
            fuelBg.CenterX();
            fuelBg.AutoSize = true;
            var ft = game.GetTexture(fuelBg.BackgroundImage);

            fuelArrow = new Box();
            Form.NewControl("fuelArrow", fuelArrow);
            fuelArrow.Size = new Vector2(8, 30);
            fuelArrow.TintColor = Color.Brown;
            UpdateGauge();

            scoreText = new Label();
            Form.NewControl("scoreText", scoreText);
            scoreText.SetColor(Color.Black);
            scoreText.Font = "Vani35";
            scoreText.Position = new Vector2(fuelBg.Position.X - 250, game.GameHeight - 120);// new Vector2(20, game.GameHeight - 120);
            scoreText.Caption = "Score";
            scoreText.DrawShadow = false;

            livesText = new Label();
            Form.NewControl("livesText", livesText);
            livesText.SetColor(Color.Black);
            livesText.Font = "Vani35";
            livesText.Position = new Vector2(fuelBg.Position.X + 400, game.GameHeight - 120);//new Vector2(320, game.GameHeight - 120);
            livesText.Caption = "Lives";
            livesText.DrawShadow = false;

            scoreValue = new FancyLabel();
            Form.NewControl("scoreValue", scoreValue);
            scoreValue.ForeColor = new Color(47, 172, 102);
            scoreValue.Font = "Vani35";
            scoreValue.Position = new Vector2(fuelBg.Position.X - 200, game.GameHeight - 80);// new Vector2(40, game.GameHeight - 80);
            scoreValue.Caption = "0";
            scoreValue.Speed *= 2;
            scoreValue.DrawShadow = false;

            livesValue = new FancyLabel();
            Form.NewControl("livesValue", livesValue);
            livesValue.ForeColor = scoreValue.ForeColor;
            livesValue.Font = scoreValue.Font;
            livesValue.Position = new Vector2(fuelBg.Position.X + 450, game.GameHeight - 80);//new Vector2(340, game.GameHeight - 80);
            livesValue.Caption = lives.ToString();
            livesValue.DrawShadow = false;
        }

        public override void Activate()
        {
            MediaPlayer.IsRepeating = false;
            game.GameBackgroundColor = Color.DarkBlue;
            game.Console.BackColor = GraphicsHelper.GetColorWithAlpha(Color.Green, 0.75f);
            game.Console.InputColor = Color.White;
            NoPlayer = false;
            half = game.GameWidth / 2.0f;
            NoPostFx = !game.Console.Ram["rr_effects"].ReturnBool();
            if (game.GraphicsDevice.DisplayMode.Height <= 600) NoPostFx = true;
#if KINECT
            game.Touch.Enabled = false;
#endif
#if SPEECH
            
#endif
            base.Activate();
        }

        public override void Deactivate(string nextScreen)
        {
#if KINECT
            game.Touch.Enabled = true;
#endif
            engineInstance.Stop();
            engineStartInstance.Stop();
            fuelInstance.Stop();
            staticInstance.Stop();
            base.Deactivate(nextScreen);
        }
        #endregion
    }
}